﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VSSpeeder
{
	public static class StringUtils
	{
		public static string Inner(this string value, string start, string end)
		{
			int startIndex = value.IndexOf(start) + start.Length;
			int endIndex = value.IndexOf(end, startIndex);
			return value.Substring(startIndex, endIndex - startIndex);
		}
		public static string End(this string value, int charsFromEnd)
		{
			if (charsFromEnd >= value.Length)
				return value;
			return value.Substring(value.Length - charsFromEnd, charsFromEnd);
		}
		public static string UpTo(this string value, string end)
		{
			if (value == null)
				return null;
			int startIndex = value.IndexOf(end);
			if (startIndex > 0)
				return value.Substring(0, startIndex);
			else
				return value;
		}
		public static string After(this string value, string from)
		{
			int startIndex = value.IndexOf(from);
			if (startIndex >= 0)
				return value.Substring(startIndex + from.Length);
			else
				return null;
		}
	}
}
